home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 2 / LSD and 17bit Compendium Deluxe - Volume II.iso / a / prog / cprog / aedoor4.lha / AEDoor.c next >
Encoding:
C/C++ Source or Header  |  1993-04-14  |  2.0 KB  |  88 lines

  1. /* 
  2. ** Name    : AEDoor.c
  3. ** Version : 1.2 
  4. ** Date    : 14 Apr 1993 
  5. ** Author  : B/\Zz/Eclipse & CFi/Eclipse 
  6. ** (c) 1993 by Eclipse. All rights reserved. 
  7. */ 
  8.  
  9.  
  10.  
  11. #include "AEDoor.h"
  12. int    __oslibversion = 37;
  13. void chkabort(void);
  14.  
  15. /*      Structures                              */
  16. struct  JHMessage       *DoorMsg;
  17. struct  MsgPort         *AEDoorPort, *AEReplyPort;
  18. struct  Process         *DoorProcess;
  19.  
  20. /*      Prototypes                              */
  21. void    SendCMD(LONG Command,LONG Data,UBYTE *String);
  22. void    SendMsg(void);
  23.  
  24. /*      Global Vars                             */
  25. UBYTE    NodeNumber;
  26. UBYTE    AEPortName[16]; 
  27. UBYTE    AEReplyName[16];
  28.  
  29. void main(int argc, char *argv[])
  30.     {
  31.     if (argc != 2)
  32.         exit(RETURN_FAIL);
  33.     
  34.     NodeNumber = argv[1][0];
  35.     sprintf(AEPortName, "AEDoorPort%lc", NodeNumber);
  36.     if (!(AEDoorPort = FindPort(AEPortName)))
  37.     exit(RETURN_FAIL);
  38.     AEReplyPort = CreateMsgPort();
  39.   DoorMsg = AllocVec(sizeof(struct JHMessage), MEMF_PUBLIC | MEMF_CLEAR);
  40.     DoorMsg->Msg.mn_Node.ln_Type = NT_MESSAGE;
  41.     DoorMsg->Msg.mn_ReplyPort = AEReplyPort;
  42.     DoorMsg->Msg.mn_Length = sizeof(struct JHMessage);
  43.     SendCMD(JH_REGISTER,0,DoorMsg->String);
  44. /* you can do your door stuff here */
  45.  
  46.  
  47. /* cleanup time                    */
  48.     SendCMD(JH_SHUTDOWN,0,"\0");
  49.     FreeVec(DoorMsg);
  50.     DeleteMsgPort(AEReplyPort);
  51.     exit(RETURN_OK);
  52.     }
  53.  
  54. /*
  55. ** SendCMD - sends an AmiExpress door command to the doorport
  56. ** Input : Command = command to execute, Data = data direction,
  57. **                 String = string to send to command
  58. ** Output: none
  59. */
  60.  
  61. void SendCMD(LONG Command,LONG Data,UBYTE *String)
  62.     {
  63.     DoorMsg->Command = Command;
  64.     DoorMsg->Data = Data;
  65.     strcpy(DoorMsg->String,String);
  66.     SendMsg();
  67.     }
  68.  
  69. /*
  70. ** SendMsg - sends a message to the ami-express door port
  71. ** Input :    None
  72. ** Output:    None
  73. */
  74.  
  75. void SendMsg(void)
  76.     {
  77.     struct Message *Msg = NULL;
  78.  
  79.     PutMsg(AEDoorPort,(struct Message *)DoorMsg);
  80.     while (Msg != DoorMsg)
  81.         {
  82.         WaitPort(AEReplyPort);
  83.         Msg = GetMsg(AEReplyPort);
  84.         if ((Msg != NULL) && (Msg != DoorMsg))
  85.             ReplyMsg(Msg);
  86.         }
  87.     }
  88.